package org.soderiakelvy.controller.reparto;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;

import org.soderiakelvy.controller.util.Constante;
import org.soderiakelvy.controller.util.SelectOneMany;
import org.soderiakelvy.model.domain.VehiculoVO;
import org.soderiakelvy.model.service.RepartoServicio;
import org.soderiakelvy.model.service.imp.RepartoServicioImp;

@ManagedBean
public class VehiculoList implements Serializable{
	private static final long serialVersionUID = -5390028555764367905L;
	
	private VehiculoVO vehiculoSelected;
	private List<VehiculoVO> vehiculos;
	private RepartoServicio service;
	
	//--- CONSTRUTCOT ---
	public VehiculoList(){
		service = new RepartoServicioImp();
		getAllVehiculos();
	}
	
	public String nuevoVehiculo(){
		return Constante.URL_VEHICULO_NEW;
	}
	
	public String prepareEdit(VehiculoVO vehiculo){
		System.out.println("bues"+vehiculo.getMarca());
		FacesContext fc = FacesContext.getCurrentInstance();
		Map<String,Object> sessionParams = fc.getExternalContext().getSessionMap();
		sessionParams.put("vehiculoEdit", vehiculo);
		return Constante.URL_VEHICULO_EDIT;
	}
	
	private void getAllVehiculos(){
		vehiculos = SelectOneMany.getAllVehiculo();
	}

	public List<VehiculoVO> getVehiculos() {
		return vehiculos;
	}

	public void setVehiculos(List<VehiculoVO> vehiculos) {
		this.vehiculos = vehiculos;
	}

	public VehiculoVO getVehiculoSelected() {
		return vehiculoSelected;
	}

	public void setVehiculoSelected(VehiculoVO vehiculoSelected) {
		this.vehiculoSelected = vehiculoSelected;
	}
	
}
